package com.example.administrator.szb.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;

import com.example.administrator.szb.R;

import java.util.ArrayList;

/**
 * Created by D N on 2017/10/14.
 */

public class MyLinearLayout extends LinearLayout {
    ArrayList<View> views = new ArrayList<>();
    public MyLinearLayout(Context context) {
        super(context);
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            views.add(getChildAt(i));
        }
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        setStatu(true);
        return super.onTouchEvent(event);
    }


    public  void setStatu(boolean flag){
        int i=0;
        for (View view : views) {

            if (i==1){
                if(flag){
                    ((CheckBox)view).setBackground(getResources().getDrawable(R.drawable.yw_choose_radiobutton2));
                }else {
                    ((CheckBox)view).setBackground(getResources().getDrawable(R.drawable.yw_choose_radiobutton));
                }

            }
            ((CheckBox)view).setChecked(flag);
            i++;
        }
    }
}
